/***********************************************************************
 * Module:  TestDaoImpl.java
 * Author:  Administrator
 * Purpose: Defines dao implementation class for class Test
 ***********************************************************************/
 
package com.feng.demo.hibernate.jta.daoimpl.hibernate;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Restrictions;

import com.feng.demo.hibernate.jta.dao.TestAmsDao;
import com.feng.demo.hibernate.jta.model.Test;
import com.feng.demo.hibernate.jta.model.TestPK;
import com.feng.demo.hibernate.jta.orm.dao.DaoException;
import com.feng.demo.hibernate.jta.orm.hibernate.dao.AmsHibernateDaoImpl;

/**
 * Class that implements methods of TestDao interface
 *
 */
public class TestAmsDaoImpl extends AmsHibernateDaoImpl implements TestAmsDao {
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#save(com.feng.baseframe.Test)
    */
   public Serializable save(Test testObject) throws DaoException{
      return super.save(testObject);
   }
      
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#load(com.feng.baseframe.TestPK)
    */
   public Test load(TestPK pk) throws DaoException{
      List cs = new ArrayList();
      String[] paramNames = new String[]{"id"};
      Object[] values = new Object[]{new Long(pk.getId())};
      for (int i=0;i<paramNames.length;i++)
         cs.add(Restrictions.eq(paramNames[i], values[i])); 
      
      List list = super.findByCriterions(Test.class, cs);
      return (((list != null) && (list.size() > 0))?(Test)list.get(0):null);
   }
  
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#delete(com.feng.baseframe.Test)
    */
   public void delete(Test testObject) throws DaoException{
      super.delete(testObject);
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#update(com.feng.baseframe.Test)
    */
   public void update(Test testObject) throws DaoException{
      super.update(testObject);
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#saveOrUpdate(com.feng.baseframe.Test)
    */
   public void saveOrUpdate(Test testObject) throws DaoException{
      super.saveOrUpdate(testObject);
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#queryByExample(java.lang.Class, com.feng.baseframe.Test)
    */
   public List queryByExample(Test testObject) throws DaoException{
      return super.queryByExample(Test.class, testObject);
   }

   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#getTestList()
    */
   public List getTestList() throws DaoException{
      return super.loadAll(Test.class);
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#getTestList(int, int)
    */
   public List getTestList(int firstResult, int maxResult){
      return super.loadAll(Test.class, firstResult, maxResult);
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#findByName(java.lang.String)
    */
   public List findByName(java.lang.String name) throws DaoException{
      List cs = new ArrayList();      
      cs.add(Restrictions.eq("name", name));      
      return super.findByCriterions(Test.class, cs);  
   }
   
   /* (non-Javadoc)
    * @see com.feng.baseframe.dao.TestDao#findByName(java.lang.String, int, int)
    */
   public List findByName(java.lang.String name, int firstResult, int maxResult) throws DaoException{
      List cs = new ArrayList();      
      cs.add(Restrictions.eq("name", name));      
      return super.findByCriterions(Test.class, cs, firstResult, maxResult); 
   }
}